import draw.*;
import geometry.*;
import tester.*;
import tester.cobertura.Instrument;

import java.util.*;
import colors.*;

@Instrument
class Player{
  /**
 * @uml.property  name="width"
 */
int width = 10;
  /**
 * @uml.property  name="height"
 */
int height = 10;
  /**
 * @uml.property  name="pos"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
Posn pos;
  /**
 * @uml.property  name="lives"
 */
int lives;
  /**
 * @uml.property  name="col"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
IColor col;
  /**
 * @uml.property  name="dir"
 */
String dir;
  /**
 * @uml.property  name="vel"
 */
int vel = 6;
  
  Player(Posn pos,int lives,IColor col){
    this.pos = pos;
    this.lives = lives;
    this.col = col;
  }
  
  //returns the coordinates of the center of the player.
  Posn center(){
	  return new Posn (this.pos.x + (width / 2), this.pos.y + (height/ 2));
  }
  
  // Draw the player to the canvas.
  boolean draw(Canvas c){
    return c.drawRect(this.pos, this.width, this.height, this.col);
  }
  
  //does nothing on tick.
  Player onTick(){
	  return this;
  }
  
  //moves the player according to the vel variable
  //in a certain direction according to key pressed.
  Player onKeyEvent(String ke){
    if (ke.equals("up")){
      return new Player(new Posn(this.pos.x, this.pos.y - vel),
    		  			this.lives, this.col); 
    } else {if (ke.equals("down")){
      return new Player(new Posn(this.pos.x, this.pos.y + vel),
    		  			this.lives, this.col); 
    } else {if (ke.equals("left")){
      return new Player(new Posn(this.pos.x - vel, this.pos.y),
    		  			this.lives, this.col);
    } else {if (ke.equals("right")){
      return new Player(new Posn(this.pos.x + vel, this.pos.y),
                        this.lives, this.col);
    } else{
      return this;      
    }}}}
  }
  
  /*
  TEMPLATE:
     FIELDS:
      ... this.width ...       -- int
      ... this.height ...      -- int
      ... this.pos ...         -- Tile
      ... this.lives ...       -- int
      ... this.col ...         -- IColor
      ... this.dir ...         -- String
      ... this.vel ...         -- int
   
      METHODS:
      ... this.onTick() ...              -- Player
      ... this.draw(Canvas c) ...        -- boolean
      ... this.center() ...              -- Posn
      ... this.onKeyEvent(String ke) ... -- Player

      METHODS FOR FIELDS:
      n/a

  */ 
}